<link rel="shortcut icon"  href="logo.ico">

<?php

$db=new PDO("sqlite:data/sms.db");

$__config__=file_get_contents("config.json");
$__config__=json_decode($__config__,1);
$__config__["site"]="http://".$_SERVER['HTTP_HOST'];
$__config__["dirpath"]=$_SERVER['DOCUMENT_ROOT'].'/tinyfilemanager/';
file_put_contents("config.json", json_encode($__config__,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));
$cu = curl_init();

curl_setopt_array($cu, [
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://127.0.0.1:8080/status",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Connection: keep-alive",
"User-Agent: PostmanRuntime-ApipostRuntime/1.1.0"
],
]);

$responses = curl_exec($cu);
$errs = curl_error($cu);

curl_close($cu);

if ($errs) {
  echo "cURL Error #:" . $errs;
} else {
  // echo $response;
}
$responses=json_decode($responses,1);

if(!$_GET["h"]){

$_curls = curl_init();

curl_setopt_array($_curls, [
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://127.0.0.1:8080/mount",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Connection: keep-alive",
"User-Agent: PostmanRuntime-ApipostRuntime/1.1.0"
],
]);

$response__ = curl_exec($_curls);
$err = curl_error($_curls);

curl_close($_curls);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  // echo $response;
}

//
$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://127.0.0.1:8080/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Connection: keep-alive",
"User-Agent: PostmanRuntime-ApipostRuntime/1.1.0"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  // echo $response;
}

}

if($_GET["h"]==1){
$__result__=$db->query("select * from sms_list")->fetchAll();
}
if($_GET["h"]==2){
$__result__=$db->query("select * from tel")->fetchAll();
}
if($_GET["h"]==3){
$__result__=$db->query("select * from sys where id=1")->fetchAll();
$__results__=json_decode($__result__[0]["values"],1);
}
if($_GET["h"]==4){
$__result__=$db->query("select * from dcim")->fetchAll();
}

if($_GET["h"]==6){
$__result__=$db->query("select * from application")->fetchAll();
}

?>
<link rel="stylesheet" type="text/css" href="style.css">

<style>.table{border-collapse:collapse;}.tbody{border-bottom-width: 1px;border-bottom-style: solid;border-color: #ccc;}.table tbody {display: block;height: 500px;overflow-y: scroll;webkit-overflow-scrolling: touch;}.table thead, .tbody tr {display: table;width: 100%;table-layout: fixed;}
	.progress{
		width: 0%;
		height: inherit;
		border-radius: 5px 5px 5px 5px;
		background: #e1e43a;
		text-align: center;
		line-height: 50px;
		color:#fff;
		font-weight: bold;
	}
	.wrapper{
		width: 100px;
		height: 50px;
		border-radius: 5px;
		background: #8d8d8d;
	}
	.xt{
		background: #8d8d8d;
	}
</style>

<script type="text/javascript" src="jquery.min.js"></script>

<img class="logo" src="logo.jpg"/>
<?php if($_GET['h']==1){?>
<a class="hcolor" href="/?h=1">SMS</a>
<?php }else{?>
<a class="" href="/?h=1">SMS</a>
<?php }?>
<?php if($_GET['h']==2){?>
<a class="hcolor" href="/?h=2">Phone</a>
<?php }else{?>
<a class="" href="/?h=2">Phone</a>
<?php }?>
<?php if($_GET['h']==3){?>
<a class="hcolor" href="/?h=3">SYS-info</a>
<?php }else{?>
<a class="" href="/?h=3">SYS-info</a>
<?php }?>
<?php if($_GET['h']==4){?>
<a class="hcolor" href="/?h=4">DCIM</a>
<?php }else{?>
<a class="" href="/?h=4">DCIM</a>
<?php }?>
<?php if($_GET['h']==5){?>
<a class="hcolor" href="/?h=5">Screen</a>
<?php }else{?>
<a class="" href="/?h=5">Screen</a>
<?php }?>
<?php if($_GET['h']==6){?>
<a class="hcolor" href="/?h=6">Application</a>
<?php }else{?>
<a class="" href="/?h=6">Application</a>
<?php }?>

<?php if($_GET['h']==7){?>
<a class="hcolor" href="/?h=7">FileManager</a>
<?php }else{?>
<a class="" href="/?h=7">FileManager</a>
<?php }?>

<br/>

<?php if($_GET["h"]){?>

<div class="div" style="height: 543px;overflow-y: scroll;">
<?php if($_GET["h"]==4){?>

<?php for($i=0;$i<count($__result__);$i++){?>
<img style="width:100px;height:auto;" src="<?php echo $__result__[$i]["path"];?>">
<?php }?>

<?php }?>

<?php if($_GET["h"]==1){?>
<table class='table'>
<thead>
<tr>
<th style="text-align:left;" width="50">Id</th>
<th style="text-align:left;" width="200">Sendphone</th>
<th width="auto">Content</th>
<th width="60">Status</th>
<th width="150">Addtime</th>
</tr>
</thead>
<tbody class="tbody">
<?php 
$p=1;
for($i=0;$i<count($__result__);$i++){?>
<tr>
<td width="50"><?php echo $p;?></td>
<td width="200"><?php echo $__result__[$i]["sendphome"];?></td>
<td width="auto"><?php echo $__result__[$i]["content"];?></td>
<td style="text-align:center;" width="60"><?php echo $__result__[$i]["status"];?></td>
<td width="150"><?php echo date("Y-m-d H:i:s",$__result__[$i]["addtime"]);?></td>
</tr>
<?php 
$p++;
}
?>
</tbody>
</table>
<?php }?>


<?php if($_GET["h"]==2){?>
<table class='table'>
<thead>
<tr style="display: block;">
<th style="text-align:left;" width="50">Id</th>
<th style="text-align:left;" width="100">Name</th>
<th style="text-align:left;" width="100">Phone</th>
</tr>
</thead>
<tbody style="border-bottom-width: 1px;border-bottom-style: solid;border-color: #ccc;">
<?php 
$p=1;
for($i=0;$i<count($__result__);$i++){?>
<tr>
<td width="50"><?php echo $p;?></td>
<td width="100"><?php echo $__result__[$i]["name"];?></td>
<td width="200"><?php echo $__result__[$i]["phone"];?></td>
</tr>
<?php 
$p++;
}?>
</tbody>
</table>
<?php }?>

<?php if($_GET["h"]==3){?>
<table class='table'>
<thead>
<tr>
<th width="300" style="text-align: left;">Key</th>
<th width="auto" style="text-align: left;">Value</th>
</tr>
</thead>
<tbody class="tbody">
<?php for($i=0;$i<count($__results__);$i++){?>
<tr>
<td width="300">
<?php
$key=[];
$key=array_keys($__results__[$i]);
echo $key[0];
?>
</td>
<td width="auto">
<?php
$value=[];
$value=array_values($__results__[$i]);
echo $value[0];
?>
</td>
</tr>
<?php }?>
</tbody>
</table>
<?php }?>

<?php if($_GET["h"]==6){?>
<table class='table'>
<thead>
<tr style="display: block;">
<th style="text-align:left;" width="50">Id</th>
<th style="text-align:left;" width="auto">Packagename</th>
</tr>
</thead>
<tbody style="border-bottom-width: 1px;border-bottom-style: solid;border-color: #ccc;">
<?php 
$p=1;
for($i=0;$i<count($__result__);$i++){?>
<tr>
<td width="50"><?php echo $p;?></td>
<td width="auto"><?php echo $__result__[$i]["packagename"];?></td>
</tr>
<?php 
$p++;
}?>
</tbody>
</table>
<?php }?>


<?php if($_GET["h"]==7){?>
<iframe frameborder="0" src="fileframe.php" style="width:100%;height:523px"></iframe>
<?php }?>



<?php if($_GET["h"]==5){?>


<div  style="display:grid;grid-template-columns: 100px 220px 450px auto;margin-top: 10px;height: 520px;">
<div></div>
<div id="screens" style="margin-top: 20px;height: 480px;">
<img  class="screens" style="width:210px;height:auto;" src="screen/screen.png">
</div>
<div style="display:grid;grid-template-rows: 130px auto">
	<div style="display:grid;grid-template-columns: 100px auto auto;margin-top: 40px;">
		<div></div>
		<div>
			<div style="display:grid;grid-template-columns: 100px 5px;">
				<div class="wrapper" style="position: relative;">
					<span class="progs" style="line-height: 50px;width: 100%;position: absolute;text-align: center;color: #fff;font-weight: bold;">0%</span>
					<div  class="progress"></div>
				</div>
				<div style="display:grid;grid-template-rows: auto 20px auto;">
					<div></div>
					<div class="xt"></div>
					<div></div>
				</div>
			</div>
		</div>
		<div></div>
	</div>
	<div style="display: grid;grid-template-columns: 100px 250px auto;">
		<div></div>
		<div>
			<div class="cpuinfo" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;"></div>
			<div class="memtotal" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;"></div>
			<div class="pmsize" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;"></div>
			<div class="df" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;"></div>
			<div class="activity" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;"></div>	
			<div class="btime" style="font-weight: bold;border-left-width: 1px;border-left-style: solid;border-top-width: 1px;border-top-style: solid;border-right-width: 1px;border-right-style: solid;border-bottom-width: 1px;border-bottom-style: solid;"></div>
		</div>
		<div></div>
	</div>
	
</div>



	<div id="container" style="height: 520px;"></div>




</div>
<?php }?>


<?php if($_GET["h"]!=4 && $_GET["h"]!=5){?>
<?php if($responses["message"]=="yes"){?>
<div style="float: right;background: #007cff;border-radius: 50px;width: 20px;height: 20px;"></div>
<?php }else{?>
<div style="float: right;background: red;border-radius: 50px;width: 20px;height: 20px;"></div>
<?php }?>
<?php }?>





</div>

<?php if($_GET["h"]==4 || $_GET["h"]==5){?>
<?php if($responses["message"]=="yes"){?>
<div style="margin-top: 2px;float: right;background: #007cff;border-radius: 50px;width: 20px;height: 20px;"></div>
<?php }else{?>
<div style="margin-top: 2px;float: right;background: red;border-radius: 50px;width: 20px;height: 20px;"></div>
<?php }?>
<?php }?>

<?php }else{?>
<div style="height: 90%;overflow-y: scroll;background: #888;"></div>
<?php }?>


<script type="text/javascript" src="js/echarts.min.js"></script>
<script type="text/javascript" src="js/echarts-gl.min.js"></script>
<script type="text/javascript" src="js/ecStat.min.js"></script>
<script type="text/javascript" src="js/dataTool.min.js"></script>
<script type="text/javascript" src="js/china.js"></script>
<script type="text/javascript" src="js/world.js"></script>
<script type="text/javascript" src="js/bmap.min.js"></script>


<script>

	var zb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3];
	var zbs=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3];
	var data1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
	var data2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];


	$(function(){
		var s=(new URL(document.location)).searchParams;
		t=s.get('h');
		if (t==5) {
			ss();
		}
	})

	function ss() {
		$.post("screen.php",{zb:zb,zbs:zbs,data1:data1,data2:data2},function(res){
			if(res.path){
				$("#screens img").attr("src",res.path);
			}
			var bf=res.battery+"%";
			if(res.battery<10){
				$(".progress").css("width",bf);
				$(".progress").css("background","red");
				$(".xt").css("background","#8d8d8d");
				$(".progs").text(bf);
			}else if(res.battery>90 && res.battery<100){
				$(".progress").css("width",bf);
				$(".progress").css("background","rgb(26, 137, 255)");
				$(".xt").css("background","#8d8d8d");
				$(".progs").text(bf);
			}else if(res.battery==100){
				$(".progress").css("width",bf);
				$(".progress").css("background","rgb(26, 137, 255)");
				$(".xt").css("background","rgb(26, 137, 255)");
				$(".progs").text(bf);
			}else{
				$(".progress").css("width",bf);
				$(".progress").css("background","#e1e43a");
				$(".xt").css("background","#8d8d8d");
				$(".progs").text(bf);
			}
			if(res.battery<95){
				$(".progress").css("border-radius","5px 0 0 5px");
			}else{
				$(".progress").css("border-radius","5px 5px 5px 5px");
			}

			$(".pmsize").text("分辨率："+res.size);
			$(".cpuinfo").text("CPU："+res.cpuinfo);
			$(".memtotal").text("内存："+res.memtotal);
			$(".btime").text("开机时间："+res.btime);
			$(".df").text("磁盘容量："+res.df[0]+"剩"+res.df[1]+"已用："+res.df[2]);
			$(".activity").text("Running："+res.activity);




			zb=res.zb;
			zbs=res.zbs;
			data1=res.data1;
			data2=res.data2;
			var dom = document.getElementById("container");
			var myChart = echarts.init(dom);
			var app = {};
			option = null;
			option = {
			    xAxis: {
			        type: 'category',
			        boundaryGap: false,
			        data: zbs
			    },
			    yAxis: {
			        type: 'value'
			    },
			    series: [{
			        data: data1,
			        type: 'line',
			        areaStyle: {}
			        // smooth: true
			    },
			    {
			        data: data2,
			        type: 'line',
			        areaStyle: {}
			        // smooth: true
			    }]
			};

			if (option && typeof option === "object") {
			    myChart.setOption(option, true);
			}

		});



		setTimeout(ss,3000);
	}


	
</script>

